import { create } from "zustand";
import { immer } from 'zustand/middleware/immer';
import { createBearSlice, BearState, BearActions } from "./bear";
import { createFishSlice, FishState, FishActions } from "./fish";
import { createBearFishSlice, BearFishActions } from "./bearfish";
import { createMealSlice, MealsState } from "./meals";

export type StoreType = BearState & BearActions & FishState & FishActions & BearFishActions & MealsState;

// MARK: 1、通过 create 创建 store，合并多个 slice store
export const useBoundStore = create<StoreType>()(
  // MARK: 2、使用 immer 可以直接修改 state
  immer((...a) => ({
    ...createBearSlice(...a),
    ...createFishSlice(...a),
    ...createBearFishSlice(...a),
    ...createMealSlice(...a),
  }))
);
